package com.spzx.product.controller;

import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.domain.CategoryBrand;
import com.spzx.product.service.CategoryBrandService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * ClassName:CategoryBrandController
 * Package:com.spzx.product.controller
 * Description:
 *
 * @Author:helei
 * @Create:2024/9/20 - 13:57
 */
@Tag(name = "分类品牌接口管理")
@RestController
@RequestMapping("/categoryBrand")
public class CategoryBrandController extends BaseController {

    @Autowired
    private CategoryBrandService categoryBrandService;

    /**
     * 查询分类品牌列表
     *
     * @param categoryBrand
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo getPageList(CategoryBrand categoryBrand) {
        startPage();
        List<CategoryBrand> categoryBrandList =
                categoryBrandService.getPageList(categoryBrand);
        return getDataTable(categoryBrandList);
    }

    /**
     * 获取分类品牌详细信息
     *
     * @param id
     * @return
     */
    @GetMapping("")
    public AjaxResult selectCategoryBrandById(Long id) {
        CategoryBrand categoryBrand = categoryBrandService.selectCategoryBrandById(id);
        return AjaxResult.success(categoryBrand);
    }

    /**
     * 新增分类品牌
     *
     * @param categoryBrand
     * @return
     */
    @PostMapping("")
    public AjaxResult addCategoryBrand(@RequestBody CategoryBrand categoryBrand) {
        boolean save = categoryBrandService.addCategoryBrand(categoryBrand);
        return toAjax(save);
    }

    /**
     * 修改分类品牌
     *
     * @param categoryBrand
     * @return
     */
    @PutMapping("")
    public AjaxResult updateCategoryBrand(@RequestBody CategoryBrand categoryBrand) {
        boolean update = categoryBrandService.updateCategoryBrand(categoryBrand);
        return toAjax(update);
    }

    /**
     * 删除分类品牌
     *
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public AjaxResult deleteCategoryBrand(@PathVariable Long[] ids) {
        boolean remove = categoryBrandService.deleteCategoryBrand(ids);
        return toAjax(remove);
    }
}